//
//  CustomPageControl.m
//  BuxProject
//
//  Created by iOS的 on 2021/12/10.
//  Copyright © 2020 Moitnea. All rights reserved.
//

#import "CustomPageControl.h"

#define kActDotW 4  //圆点的宽度
#define kActMagrin 8 //圆点之间的间隔
@implementation CustomPageControl

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //计算圆点尺寸和间距的长度
    CGFloat marginX = kActDotW + kActMagrin;
    //计算整个pageControll的宽度
    CGFloat newW = self.frame.size.width;//(self.subviews.count - 1 ) * magrin + self.subviews.count *dotW;
    //计算左边距
    CGFloat leftRight = (newW - ((self.subviews.count - 1 ) * kActMagrin + self.subviews.count * kActDotW)) / 2;
    //设置新frame
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, newW, self.frame.size.height);
    //遍历subview,设置圆点frame
    for (int i=0; i<[self.subviews count]; i++) {
        UIImageView* dot = [self.subviews objectAtIndex:i];
        if (@available(iOS 14.0, *)) {
            
        } else {
            [dot setFrame:CGRectMake(i * marginX + leftRight, dot.frame.origin.y, kActDotW, kActDotW)];
        }
    }
}

@end
